package com.xiyu.service.model.mailbox.mail;

import org.babyfish.jimmer.sql.JSqlClient;
import org.babyfish.jimmer.sql.TransientResolver;
import org.babyfish.jimmer.sql.ast.tuple.Tuple2;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Component
public class MailboxMailBlindReceiverResolver implements TransientResolver<Long, List<Long>> {
    private final JSqlClient sqlClient;

    // 构造注入
    public MailboxMailBlindReceiverResolver(JSqlClient sqlClient) {
        this.sqlClient = sqlClient;
    }

    @Override
    public Map<Long, List<Long>> resolve(Collection<Long> ids) {
        return Tuple2.toMultiMap(sqlClient
                .createQuery(MailboxMailReceiverTable.$)
                .where(MailboxMailReceiverTable.$.mailId().in(ids))
                .where(MailboxMailReceiverTable.$.type().eq(2))
                .select(MailboxMailReceiverTable.$.mailId(), MailboxMailReceiverTable.$.id())
                .execute());
    }


    @Override
    public List<Long> getDefaultValue() {
        return Collections.emptyList();
    }
}
